// FileManager.h provides the attributes of the FileManager class.
// All interaction with external files will go through this class so that this class controls all the
// ordering and formatting of the external files.
//-----------------

#if !defined( FileManagerH)
#define FileManagerH

//-----------------
// Includes various libraries and files
#include <cassert>		// for asserts
#include <d3dx9.h>		// Direct 3D library (for all Direct 3D functions)
#include <fstream>
#include <list>
#include <string>
#include <sstream>
#include <vector>

#include "AudioAsset.h"
#include "constants.h"
#include "EndPosition.h"
#include "ModelAsset.h"
#include "PlacedObject.h"
#include "Player.h"
#include "WorldObject.h"
//-----------------

class FileManager {
	public:
		// constructor and destructor
		FileManager( LPDIRECT3DDEVICE9 device);
		~FileManager();

		// accessors
		void extract_models_and_audio( std::vector<Mesh>* models) const;
		void extract_previous_assets( std::vector<Mesh>* models, std::list<ModelAsset>& list_models, std::list<AudioAsset>& list_audio, std::list<std::string>& list_ignored) const;
		bool is_valid_format( const std::string& file, const std::string& type) const;

		void export_assets( std::list<ModelAsset>& list_models, std::list<AudioAsset>& list_audio, std::list<std::string>& list_ignored) const;
		void export_module( std::vector<std::vector<PlacedObject>>& vector_floor, std::vector<std::vector<PlacedObject>>& vector_models, std::list<AudioAsset>& list_audio, const std::string& file_name) const;

		void import_module_to_toolset( std::vector<Mesh>* models, std::vector<std::vector<PlacedObject>>& vector_floor, std::vector<std::vector<PlacedObject>>& vector_models, std::list<AudioAsset>& list_audio, const int& FLOOR, const std::string& file_name) const;
		void import_essential_module_data( const std::string& file_name, int& total_levels) const;
		void import_level_from_module( std::vector<Mesh>* models, std::vector<WorldObject*>& vector_models, WorldObject& skybox, std::vector<AudioAsset*>& vector_audio, Player* p_player, std::vector<EndPosition>& end_positions, const std::string& file_name, const int& level) const;

	private:
		// functions for importing based on the version of the module file
		void import_module_to_toolset_1_0( std::vector<Mesh>* models, std::vector<std::vector<PlacedObject>>& vector_floor, std::vector<std::vector<PlacedObject>>& vector_models, std::list<AudioAsset>& list_audio, const int& FLOOR, std::ifstream& input_file) const;
		void import_module_to_toolset_1_1( std::vector<Mesh>* models, std::vector<std::vector<PlacedObject>>& vector_floor, std::vector<std::vector<PlacedObject>>& vector_models, std::list<AudioAsset>& list_audio, const int& FLOOR, std::ifstream& input_file) const;

		void import_level_from_module_1_0( std::vector<Mesh>* models, std::vector<WorldObject*>& vector_models, WorldObject& skybox, std::vector<AudioAsset*>& vector_audio, Player* p_player, std::vector<EndPosition>& end_positions, std::ifstream& input_file, const int& level) const;
		void import_level_from_module_1_1( std::vector<Mesh>* models, std::vector<WorldObject*>& vector_models, WorldObject& skybox, std::vector<AudioAsset*>& vector_audio, Player* p_player, std::vector<EndPosition>& end_positions, std::ifstream& input_file, const int& level) const;

		// utility functions that shouldn't be accessed outside this class
		void extract_asset_from_file( std::vector<Mesh>* models, std::list<ModelAsset>& list_models, std::list<AudioAsset>& list_audio, std::list<std::string>& list_ignored, std::ifstream& input_file, std::string& word) const;
		void get_asset_dimensions( WorldObject& a) const;
		std::string get_sentence( std::ifstream& input_file, const std::string& end_condition) const;
		std::string get_word( std::ifstream& input_file, const char& end_condition) const;

		LPDIRECT3DDEVICE9 device_;
};

#endif